package com.tedu.day1_25.p3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");

        Channel c=f.newConnection().createChannel();

//        定义direct类型交换机，direct_logs
        c.exchangeDeclare("topic_logs", BuiltinExchangeType.TOPIC);
        while (true){
            System.out.println("enter message:");
            String s=new Scanner(System.in).nextLine();
            System.out.println("enter route:");
            String key=new Scanner(System.in).nextLine();

            c.basicPublish("topic_logs", key, null, s.getBytes());
        }
    }
}
